// 设置
export function setItem(key, value, isSession = false) {
  const storage = isSession ? window.sessionStorage : window.localStorage
  if (typeof value === 'object') {
    value = JSON.stringify(value)
  }
  storage.setItem(key, value)
}

// 获取
export function getItem(key, isSession = false) {
  const storage = isSession ? window.sessionStorage : window.localStorage
  const value = storage.getItem(key)
  try {
    return JSON.parse(value)
  } catch (err) {
    return value
  }
}

// 删除
export function removeItem(key, isSession = false) {
  const storage = isSession ? window.sessionStorage : window.localStorage
  storage.removeItem(key)
}
